//index.js
//获取应用实例
const app = getApp()
const ctx = wx.createCanvasContext('drawBoard')
let point = {}

Page({
  data: {
    point: {
      x: 0,
      y: 0
    }
  },
  canvasIdErrorCallback: function (e) {
    console.error(e.detail.errMsg)
  },
  onReady: function (e) {
    // 使用 wx.createContext 获取绘图上下文 context
    ctx.setLineJoin('round');
    ctx.setLineCap('round')
    ctx.setFillStyle('red')
    ctx.setStrokeStyle('black')
    ctx.setLineWidth(10)
    ctx.save();
  },
  start: function (e) {
    console.log(e)
    ctx.beginPath();
    point = {
      x: e.touches[0].x,
      y: e.touches[0].y
    }

    ctx.moveTo(point.x, point.y)

  },
  move: function (e) {
    console.log(e)

    let np = {
      x: e.touches[0].x,
      y: e.touches[0].y
    }
    ctx.quadraticCurveTo(point.x, point.y, np.x, np.y);
    point = np;
    ctx.stroke()
    ctx.draw(true);

    ctx.moveTo(np.x, np.y)
  },
  end: function (e) {
    console.log(e)

    ctx.closePath()
  }
})
